package com.yikaiye.android.yikaiye.ui.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.DataBindingHolder;
import com.google.gson.Gson;
import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.databinding.ItemInServiceStepBinding;
import com.yikaiye.android.yikaiye.model.ServiceDetailsModel;

public class InServiceStepAdapter extends BaseQuickAdapter<ServiceDetailsModel.ServiceNodeModel, DataBindingHolder<ItemInServiceStepBinding>> {

    private Context context;
    private int mStatus;

    public InServiceStepAdapter(Context context, int status) {
        this.context = context;
        this.mStatus = status;
    }

    @Override
    protected void onBindViewHolder(@NonNull DataBindingHolder<ItemInServiceStepBinding> itemInServiceStepBindingDataBindingHolder, int i, @Nullable ServiceDetailsModel.ServiceNodeModel serviceNodeModel) {
        ItemInServiceStepBinding binding = itemInServiceStepBindingDataBindingHolder.getBinding();
        if (serviceNodeModel != null) {
            binding.stepTv.setText(serviceNodeModel.getNodeName());
            if (mStatus == 2) {
                binding.stepTv.setTextColor(ContextCompat.getColor(context, R.color.color_3b3a40));
                binding.iv.setImageResource(R.mipmap.img_v);
            } else if (mStatus == 1) {
                // 节点状态：0.待服务 1.服务中 2.已完成
                if (serviceNodeModel.getStatus() != null) {
                    if (serviceNodeModel.getStatus() == 0) {
                        binding.stepTv.setTextColor(ContextCompat.getColor(context, R.color.color_9b9b9b));
                        binding.iv.setVisibility(View.INVISIBLE);
                        binding.dotLineLl.setVisibility(View.GONE);
                        binding.lineLl.setVisibility(View.VISIBLE);
                        binding.line.setBackgroundColor(ContextCompat.getColor(context, R.color.color_c3c3c3));
                    } else if (serviceNodeModel.getStatus() == 1) {
                        binding.stepTv.setTextColor(ContextCompat.getColor(context, R.color.color_f93f50));
                        binding.iv.setVisibility(View.VISIBLE);
                        binding.dotLineLl.setVisibility(View.VISIBLE);
                        binding.lineLl.setVisibility(View.GONE);
                    } else if (serviceNodeModel.getStatus() == 2) {
                        binding.stepTv.setTextColor(ContextCompat.getColor(context, R.color.color_f93f50));
                        binding.iv.setVisibility(View.VISIBLE);
                        binding.dotLineLl.setVisibility(View.GONE);
                        binding.lineLl.setVisibility(View.VISIBLE);
                        binding.line.setBackgroundColor(ContextCompat.getColor(context, R.color.color_3b3a40));
                    }
                }
            }
//            float dpHeight;
//            if (i == 0 || i == getItemCount() - 1 && getItemCount() > 2) {
//                dpHeight = 40;
//            } else {
//                dpHeight = 20;
//            }
//            float pxHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpHeight, context.getResources().getDisplayMetrics());
//            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) pxHeight);
//            binding.container.setLayoutParams(layoutParams);
        }
    }

    @NonNull
    @Override
    protected DataBindingHolder<ItemInServiceStepBinding> onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new DataBindingHolder<>(R.layout.item_in_service_step, viewGroup);
    }
}
